package scsc.pm;

import java.util.ArrayList;
import java.util.List;

import scsc.pub.data.SwimlaneOperator;
import scsc.pub.data.SwimlaneOperatorPK;
import scsc.pub.db.DBManage;
import scsc.pub.db.PageListData;
import scsc.pub.exception.UnifyUserException;
import scsc.pub.tools.Logger;
import scsc.pub.tools.StringUtil;
import scsc.web.system.data.SysSwimlaneOperatorData;

public class SysSwimlaneOperator {
	private static Logger logger = Logger.getLogger(SysOperatorGroup.class);

	/**
	 * create
	 */
	public void createSwimlaneOperator(DBManage dbmanage,
			SysSwimlaneOperatorData swimlaneOperatorData)
			throws UnifyUserException {

		SwimlaneOperator data = new SwimlaneOperator();
		SwimlaneOperatorPK pk = new SwimlaneOperatorPK();
		pk.setOperatorId(swimlaneOperatorData.getOperatorId());
		pk.setSwimlaneId(swimlaneOperatorData.getSwimlaneId());
		data.setComp_id(pk);
		dbmanage.sqlSave(data);
	}

	/**
	 * delete
	 */
	public void deleteSwimlaneOperator(DBManage dbmanage, String operatorId,
			Long swimlaneId) throws UnifyUserException {
		operatorId = StringUtil.trim(operatorId);
		String sqlStr = "delete from scsc.pub.data.SwimlaneOperator as so where 1=1";
		if (operatorId.length() > 0) {
			sqlStr = sqlStr + " and so.comp_id.operatorId='" + operatorId + "'";
		}
		if (swimlaneId != null) {
			sqlStr = sqlStr + " and so.comp_id.swimlaneId=" + swimlaneId;
		}
		dbmanage.sqlDelete(sqlStr);
	}

	/**
	 * select
	 */
	public void selectSwimlaneOperator(DBManage dbmanage, String operatorId,
			Long swimlaneId, PageListData footer) {

		String sqlStr = "select new scsc.web.system.data.SysSwimlaneOperatorData(so.comp_id.operatorId,so.comp_id.swimlaneId,operator.operatorname,operator.operatorname) from scsc.pub.data.SwimlaneOperator as so,scsc.pub.data.Operator as operator where so.comp_id.operatorId=operator.operatorid";
		if (operatorId.length() > 0) {
			sqlStr = sqlStr + " and so.comp_id.operatorId like '%" + operatorId
					+ "%'";
		}
		if (swimlaneId != null) {
			sqlStr = sqlStr + " and so.comp_id.swimlaneId =" + swimlaneId;
		}
		dbmanage.sqlQueryPage(sqlStr, footer);
	}

	public ArrayList selectSwimlaneOperator(DBManage dbmanage,
			String operatorId, Long swimlaneId) {
		String sqlStr = "select new scsc.web.system.data.SysSwimlaneOperatorData(so.comp_id.operatorId,so.comp_id.swimlaneId,operator.operatorname,operator.operatorname) from scsc.pub.data.SwimlaneOperator as so,scsc.pub.data.Operator as operator where so.comp_id.operatorId=operator.operatorid";
		if (operatorId.length() > 0) {
			sqlStr = sqlStr + " and so.comp_id.operatorId like '%" + operatorId
					+ "%'";
		}
		if (swimlaneId != null) {
			sqlStr = sqlStr + " and so.comp_id.swimlaneId =" + swimlaneId;
		}
		List result = dbmanage.sqlQuery(sqlStr);
		return (ArrayList) result;
	}

	public java.util.ArrayList selectNoSwimlaneOperator(DBManage dbmanage,
			Long swimlaneId) {
		String sqlStr = "select new scsc.web.system.data.SysOperatorData(operator.operatorid,operator.operatorname,operator.deptcode,operator.deptcode,operator.password,operator.regdate,operator.lastpassword,operator.lifecycle,operator.stat)  from scsc.pub.data.Operator as operator where operator.operatorid not in (select distinct so.comp_id.operatorId from scsc.pub.data.SwimlaneOperator as so where so.comp_id.swimlaneId="
				+ swimlaneId + ")";
		List result = dbmanage.sqlQuery(sqlStr);
		return (ArrayList) result;
	}
}
